// pages/myOrder/myOrder.js

const {
    getMyAllGiftByIsPost
} = require('../../services/myGiftsReq');

// const { formatTime } = require('../../utils/util');



Page({

    /**
     * 页面的初始数据
     */
    data: {
        orderList: [],
        isPost: 0,
        myUserId: null,
        pageNum: 1,
        pageSize: 10,
        isFinish: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.handleGetMyAllGiftByIsPost();
    },
    onReachBottom() {
        this.handleGetMyAllGiftByIsPost();
    },

    handleGetOrder(e) {
        console.log(e);
        // 将所有的元素直接初始化
        this.setData({
            pageNum: 1,
            pageSize: 10,
            isFinish: false,
            index: e.detail.index,
            orderList: []
        })
        this.handleGetMyAllGiftByIsPost()


    },
    handleGetMyAllGiftByIsPost() {
        let {
            pageNum,
            pageSize,
            isFinish,
            orderList,
            index
        } = this.data;
        console.log(index);
        index = index ?? 0;

        if (isFinish) return wx.showToast({
            title: '到底了',
            icon: "error"
        });

        let params = {
            pageNum,
            pageSize,
            isPost: index
        }
        getMyAllGiftByIsPost(params, res => {
            console.log(res.data.data);
            this.setData({
                orderList: res.data.data.list.concat(orderList),
                isFinish: orderList.length >= res.data.data.totalCount,
                pageNum: pageNum + 1,
                pageSize: pageSize,
            })
        })
    },
    handleGetInfoGoods(e) {
        console.log(e);
    },

    handleGetCourseOrder() {

    },
    handleActivityGetOrder() {

    }
})